<template>
    <!-- 对话框表单 -->
    <el-dialog
        class="ba-operate-dialog"
        :close-on-click-modal="false"
        :model-value="baTable.form.operate ? true : false"
        @close="baTable.toggleForm"
    >
        <template #header>
            <div class="title" v-drag="['.ba-operate-dialog', '.el-dialog__header']" v-zoom="'.ba-operate-dialog'">
                {{ baTable.form.operate ? t(baTable.form.operate) : '' }}
            </div>
        </template>
        <el-scrollbar v-loading="baTable.form.loading" class="ba-table-form-scrollbar">
            <div
                class="ba-operate-form"
                :class="'ba-' + baTable.form.operate + '-form'"
                :style="'width: calc(100% - ' + baTable.form.labelWidth! / 2 + 'px)'"
            >
                <el-form
                    v-if="!baTable.form.loading"
                    class="flex"
                    ref="formRef"
                    @keyup.enter="baTable.onSubmit(formRef)"
                    :model="baTable.form.items"
                    label-position="right"
                    :label-width="baTable.form.labelWidth + 'px'"
                    :rules="rules"
                >
                <FormItem :label="t('xCarinfo.BRAND')" type="string" v-model="baTable.form.items!.BRAND" prop="BRAND" :input-attr="{ placeholder: t('Please input field', { field: t('xCarinfo.BRAND') }) }" />
                <FormItem :label="t('xCarinfo.CORP')" type="string" v-model="baTable.form.items!.CORP" prop="CORP" :input-attr="{ placeholder: t('Please input field', { field: t('xCarinfo.CORP') }) }" />
                <FormItem :label="t('xCarinfo.TRUCKNO')" type="string" v-model="baTable.form.items!.TRUCKNO" prop="TRUCKNO" :input-attr="{ placeholder: t('Please input field', { field: t('xCarinfo.TRUCKNO') }) }" />
                <FormItem :label="t('xCarinfo.CARFLAG')" type="string" v-model="baTable.form.items!.CARFLAG" prop="CARFLAG" :input-attr="{ placeholder: t('Please input field', { field: t('xCarinfo.CARFLAG') }) }" />
                <FormItem :label="t('xCarinfo.ZBWEIGHT')" type="number" prop="ZBWEIGHT" v-model.number="baTable.form.items!.ZBWEIGHT" :input-attr="{ step: '0.01', placeholder: t('Please input field', { field: t('xCarinfo.ZBWEIGHT') }) }" />
                <FormItem :label="t('xCarinfo.AXLE')" type="string" v-model="baTable.form.items!.AXLE" prop="AXLE" :input-attr="{ placeholder: t('Please input field', { field: t('xCarinfo.AXLE') }) }" />
                <FormItem :label="t('xCarinfo.QYWEIGHT')" type="number" prop="QYWEIGHT" v-model.number="baTable.form.items!.QYWEIGHT" :input-attr="{ step: '0.01', placeholder: t('Please input field', { field: t('xCarinfo.QYWEIGHT') }) }" />
                <FormItem :label="t('xCarinfo.ABS')" type="string" v-model="baTable.form.items!.ABS" prop="ABS" :input-attr="{ placeholder: t('Please input field', { field: t('xCarinfo.ABS') }) }" />
                <FormItem :label="t('xCarinfo.FIRSTDATE')" type="datetime" v-model="baTable.form.items!.FIRSTDATE" prop="FIRSTDATE" :input-attr="{ placeholder: t('Please select field', { field: t('xCarinfo.FIRSTDATE') }) }" />
                <FormItem :label="t('xCarinfo.HDWEIGHT')" type="number" prop="HDWEIGHT" v-model.number="baTable.form.items!.HDWEIGHT" :input-attr="{ step: '0.01', placeholder: t('Please input field', { field: t('xCarinfo.HDWEIGHT') }) }" />
                <FormItem :label="t('xCarinfo.GPS')" type="string" v-model="baTable.form.items!.GPS" prop="GPS" :input-attr="{ placeholder: t('Please input field', { field: t('xCarinfo.GPS') }) }" />
                <FormItem :label="t('xCarinfo.JYDATE')" type="datetime" v-model="baTable.form.items!.JYDATE" prop="JYDATE" :input-attr="{ placeholder: t('Please select field', { field: t('xCarinfo.JYDATE') }) }" />
                <FormItem :label="t('xCarinfo.GPSSHIP')" type="string" v-model="baTable.form.items!.GPSSHIP" prop="GPSSHIP" :input-attr="{ placeholder: t('Please input field', { field: t('xCarinfo.GPSSHIP') }) }" />
                <FormItem :label="t('xCarinfo.SIZE')" type="string" v-model="baTable.form.items!.SIZE" prop="SIZE" :input-attr="{ placeholder: t('Please input field', { field: t('xCarinfo.SIZE') }) }" />
                <FormItem :label="t('xCarinfo.ROADDATE')" type="string" v-model="baTable.form.items!.ROADDATE" prop="ROADDATE" :input-attr="{ placeholder: t('Please input field', { field: t('xCarinfo.ROADDATE') }) }" />
                <FormItem :label="t('xCarinfo.VDSIVMS')" type="string" v-model="baTable.form.items!.VDSIVMS" prop="VDSIVMS" :input-attr="{ placeholder: t('Please input field', { field: t('xCarinfo.VDSIVMS') }) }" />
                <FormItem :label="t('xCarinfo.POLICYNO')" type="string" v-model="baTable.form.items!.POLICYNO" prop="POLICYNO" :input-attr="{ placeholder: t('Please input field', { field: t('xCarinfo.POLICYNO') }) }" />
                <FormItem :label="t('xCarinfo.ROADNUMBER')" type="number" prop="ROADNUMBER" v-model.number="baTable.form.items!.ROADNUMBER" :input-attr="{ step: '1', placeholder: t('Please input field', { field: t('xCarinfo.ROADNUMBER') }) }" />
                <FormItem :label="t('xCarinfo.POLICYDATE')" type="datetime" v-model="baTable.form.items!.POLICYDATE" prop="POLICYDATE" :input-attr="{ placeholder: t('Please select field', { field: t('xCarinfo.POLICYDATE') }) }" />
                <FormItem :label="t('xCarinfo.POLICYTYPE')" type="string" v-model="baTable.form.items!.POLICYTYPE" prop="POLICYTYPE" :input-attr="{ placeholder: t('Please input field', { field: t('xCarinfo.POLICYTYPE') }) }" />
                 <FormItem :label="t('xCarinfo.STATUS')" type="switch" v-model="baTable.form.items!.STATUS" prop="STATUS"   />
                <FormItem :label="t('xCarinfo.LOADTYPE')" type="string" v-model="baTable.form.items!.LOADTYPE" prop="LOADTYPE" :input-attr="{ placeholder: t('Please input field', { field: t('xCarinfo.LOADTYPE') }) }" />
                <FormItem style="width: 100%" :label="t('xCarinfo.SCOPE')" type="string" v-model="baTable.form.items!.SCOPE" prop="SCOPE" :input-attr="{ placeholder: t('Please input field', { field: t('xCarinfo.SCOPE') }) }" />
                <FormItem style="width: 100%" :label="t('xCarinfo.DEMO')" type="textarea" v-model="baTable.form.items!.DEMO" prop="DEMO" :input-attr="{ rows: 3, placeholder: t('Please input field', { field: t('xCarinfo.DEMO') }) }" @keyup.enter.stop="" @keyup.ctrl.enter="baTable.onSubmit(formRef)" />
                <FormItem :label="t('xCarinfo.OP')" type="string" v-model="baTable.form.items!.OP" prop="OP" :input-attr="{ placeholder: t('Please input field', { field: t('xCarinfo.OP') }) }" />
                <FormItem :label="t('xCarinfo.OPTIME')" type="datetime" v-model="baTable.form.items!.OPTIME" prop="OPTIME" :input-attr="{ placeholder: t('Please select field', { field: t('xCarinfo.OPTIME') }) }" />
                <FormItem :label="t('xCarinfo.PHOTO')" type="image" v-model="baTable.form.items!.PHOTO" prop="PHOTO" :input-attr="{ placeholder: t('Please input field', { field: t('xCarinfo.PHOTO') }) }" />
                </el-form>
            </div>
        </el-scrollbar>
        <template #footer>
            <div :style="'width: calc(100% - ' + baTable.form.labelWidth! / 1.8 + 'px)'">
                <el-button @click="baTable.toggleForm('')">{{ t('Cancel') }}</el-button>
                <el-button v-blur :loading="baTable.form.submitLoading" @click="baTable.onSubmit(formRef)" type="primary">
                    {{ baTable.form.operateIds && baTable.form.operateIds.length > 1 ? t('Save and edit next item') : t('Save') }}
                </el-button>
            </div>
        </template>
    </el-dialog>
</template>

<script setup lang="ts">
import { reactive, ref, inject } from 'vue'
import { useI18n } from 'vue-i18n'
import type baTableClass from '/@/utils/baTable'
import FormItem from '/@/components/formItem/index.vue'
import type { ElForm, FormItemRule } from 'element-plus'
import { buildValidatorData } from '/@/utils/validate'


const formRef = ref<InstanceType<typeof ElForm>>()
const baTable = inject('baTable') as baTableClass

const { t } = useI18n()

const rules: Partial<Record<string, FormItemRule[]>> = reactive({
    FIRSTDATE: [buildValidatorData({name: 'date', message: t('Please enter the correct field', { field: t('xCarinfo.FIRSTDATE') })})],
    JYDATE: [buildValidatorData({name: 'date', message: t('Please enter the correct field', { field: t('xCarinfo.JYDATE') })})],
    POLICYDATE: [buildValidatorData({name: 'date', message: t('Please enter the correct field', { field: t('xCarinfo.POLICYDATE') })})],
    OPTIME: [buildValidatorData({name: 'date', message: t('Please enter the correct field', { field: t('xCarinfo.OPTIME') })})],
})

</script>

<style scoped lang="scss"></style>
